﻿using FreeBroker.Properties;
using System.IO;

namespace FreeBroker
{
    public static class Config
    {
        private static BrokerConfiguration broker;

        public static BrokerConfiguration Broker
        {
            get 
            {
                if (broker == null)
                {
                    Load();
                }
                return broker; 
            }
        }

        public static void Load()
        {
            // Check if config file really exists
            if (File.Exists(Settings.Default.BrokerConfigFile))
            {
                Config.broker = ObjectXMLSerializer<BrokerConfiguration>.Load(Settings.Default.BrokerConfigFile);
            }
            else
            {
                // File doesn't exist, create new object
                Config.broker = new BrokerConfiguration();
            }
        }

        public static void Save()
        {
            ObjectXMLSerializer<BrokerConfiguration>.Save(Config.broker, Settings.Default.BrokerConfigFile);
        }
    }
}
